<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport"
	content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<link rel="stylesheet" href="/assets/css/admin.css">
<link rel="stylesheet" href="/assets/css/bootstrap.min.css">
<script src="/assets/js/jquery-1.11.0.min.js"></script>
<script src="/assets/js/bootstrap.min.js"></script>
<script src="/assets/js/adminsg.js"></script>
<script src="/assets/js/axios.min.js"></script>
<title>人车人</title><link rel="icon" href="/assets/img/titleico.ico" type="image/x-icon">
<style type="text/css">
.headbody {
	padding: 0px;
	height: 10%;
	margin-bottom: -29px;
}

.bgmdl {
	background-color: #0099FF;
	padding: 0px;
	width: 100%;
	height: 6px;
	margin: 0px;
}

.bodybg {
	background: url("/assets/img/login_bg.jpg");
	-webkit-background-size: cover;
	-moz-background-size: cover;
	-o-background-size: cover;
	background-size: cover;
	height: 88%;
}

.login-panel {
	height: 240px;
	width: 400px;
	border-radius: 5px;
}

.center-vertical {
	position: relative;
	top: 50%;
	transform: translateY(-50%);
}

.buttombody {
	background: url("/assets/img/logo-botom.png");
	height: 5%;
	margin-top: -5px;
}

.center-vertical .form-group {
	position: relative;
}

.center-vertical .form-group .yzm {
	position: absolute;
	top: 7px;
	right: 7px;
	width: 120px;
	border: 1px solid #ccc
}
</style>
</head>
<body>
	#@confirm()
	#@alertsh()
	<div id="headbody" class="container-fuild headbody">
		<img src="/assets/img/logo.png" style="height: 30px;">
<!-- 		<div class="row bgmdl"></div> -->
	</div>
	<div class="bodybg">
		<div class="login-panel center-block center-vertical">
			<form id="loginForm" class="form col-md-12 center-block"
				onsubmit="return false;">
				<br> <br>
				<div class="form-group">
					<input type="text" class="form-control input-lg" placeholder="用户名"
						name="account">
				</div>
				<div class="form-group">
					<input type="password" class="form-control input-lg"
						placeholder="登录密码" name="passWord">
				</div>
				<div class="form-group">
					<input id="vcode" type="text" class="form-control input-lg"
						placeholder="验证码" name="vcode"> <img id="yzm" class="yzm" />
				</div>
				<div style="margin-bottom: 15px;"><a href="javascript:;" id="resetpas">忘记密码？</a></div>
				
				<div class="form-group">
					<button id="submitBtn" class="btn btn-primary btn-lg btn-block">立刻登录</button>
				</div>
			</form>
		</div>
	</div>
	<div class="buttombody container-fuild" id="buttombody">
		<p class="center-vertical" style="color: #fff">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			云南人车人信息技术服务有限公司 400-870-7776</p>
	</div>
</body>
<script>
	$(document).ready(function(){
		getVcode()	

		function getVcode(){
			$.ajax({
				type:"post",
				url:"/adminLogin/vcode",
				success:function(data){
					if(data.code!=0){
						#("yzm").src=data.path;
					}
				}
			})
		}
		$("#vcode").on("focus",function(){
			if (#("yzm").style.display=="none") {
				#("yzm").style.display="";
				getVcode();
			}
		})
		$("#yzm").on("click",function(){
			getVcode();
		})
		$("#submitBtn").on("click",function(){
			var formData = $("#loginForm").serialize();
			$.ajax({
				type:"post",
				url:"/adminLogin/login",
				data:formData,
				success:function(data){
					if(data.code==1){
						if (data.repeatLogin) {
							alert("该账户已在其他设备登陆，如非本人操作，请尽快修改密码！");
						}
						location.href="/admin";
					}else{
						alert(data.msg);
					}
				}
			})
		})
		
		var alert_confirm = $("#alert_confirm")
		$("#resetpas").click(function(){
			var opt = {
				isShowBg: false,
				text: "<div class='selbox'>"+
					  "    <div class='box active' style='width: 50%;margin: 0 auto;'>"+
					  "        <div class='input-group'><input class='form-control phone' style='border-radius: 4px 0 0 4px;' type='type' placeholder='手机号码' /><span class='input-group-btn'><button class='btn btn-default getyzm-hook' style='border-radius: 0px 4px 4px 0;' type='button' data-loading-text='正在发送...'>获取验证码</button></span></div>"+
					  "        <div><input style='margin: 10px 0;' class='form-control yzm' type='type' placeholder='短信验证码' /></div>"+
					  "        <div><input style='margin: 10px 0;' class='form-control newpas' type='password' placeholder='新密码' /></div>"+
					  "        <div><input class='form-control reaptepas' type='password' placeholder='确认密码' /></div>"+
					  "	       <p class='err' style='color: #a94442;margin: 0;font-size: 16px;line-height: 38px;'></p>"+
					  "    </div>"+
					  "</div>",
				fn: function(modalDom,btn,callback){
					if(yz(modalDom.find(".modal-body").find(".active").find("input"))){
						var data = {}
							data.yzm = modalDom.find("input.yzm").val()
							data.password = modalDom.find(".active").find("input.newpas").val()
							axios.post("/adminLogin/setPassWord",_x.qsStringify(data))
							.then(function(res){
								console.log(res)
								if(res.data.code == 1){
									callback()
									_x.show_alert_sh(res.data.msg,true)
								}else{
									_x.show_alert_sh(res.data.msg,false)
									btn.button('reset')
								}
							})
							.catch(function(){
								_x.show_alert_sh("修改失败！",false)
								btn.button('reset')
							})
					}else{
						btn.button('reset')
					}
				}
			}
			_x.show_alert_confirm(opt)
		})
		
		//0原密码 1短信
		alert_confirm.on("click",".changebtn",function(){
			var index = $(this).index()
			alert_confirm.find(".selbox").children(".box").removeClass("active").hide().eq(index).addClass("active").show()
			alert_confirm.find("button.confirm").attr("subtype",index)
		})
		
		//获取验证码
		alert_confirm.on("click",".getyzm-hook",function(){
			var that = $(this)
			
			if(yz(that.parent().siblings("input"))){
				that.button('loading')
				var data = {}
				data.userPhone = that.parent().siblings("input").val()
				axios.post("/adminLogin/getForgetCode",_x.qsStringify(data))
				.then(function(res){
					if(res.data.code == 1){
						countDown(that)
					}else{
						_x.show_alert_sh(res.data.msg,false)
						that.button('reset')
					}
				})
				.catch(function(){
					_x.show_alert_sh("验证码发送失败！",false)
					that.button('reset')
				})
			}
		})
		
		function countDown(dom){
			var timer = null,
				second = 120
			timer = setInterval(function(){
				second--
				dom.text(second + "s后重新发送")
				if(second <= 0){
					dom.button('reset').text("获取验证码")
					clearInterval(timer)
				}
			},1000)
		}
		
		function yz(input){
			var mark = true
			input.each(function(){
				var that = $(this),
					val = that.val(),
					errDom = that.parents(".active").children(".err")
				if(_x.isEmpty(val)){
					mark = false
					errDom.text(that.attr("placeholder") + "不能为空！")
					that.parent().addClass("has-error")
				}else{
					that.parent().removeClass("has-error")
				}
				
				if(that.hasClass("newpas")){
					if(val != that.parents(".active").find(".reaptepas").val()){
						mark = false
						errDom.text("两次密码不一致！")
						that.parent().addClass("has-error")
					}
				}
				
				if(that.hasClass("reaptepas")){
					if(val != that.parents(".active").find(".newpas").val()){
						mark = false
						errDom.text("两次密码不一致！")
						that.parent().addClass("has-error")
					}
				}
			})
			
			return mark
		}
	})
</script>
</html>